Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 25, 2025

Move test_os.py and test_posix.py into a new test_os package.

Move test_os.py and test_posix.py into a new test_os package.
Fix test_fs_holes(): use "w+b" mode, and delete the file once done.
@vstinner vstinner marked this pull request as draft September 25, 2025 14:36
@vstinner
Copy link
Member Author

@vstinner vstinner marked this pull request as ready for review September 26, 2025 19:36
@vstinner
Copy link
Member Author

I consider that the PR is now ready for a review :-)

Copy link
Contributor

@cmaloney cmaloney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. If there's any new changes in test_os or test_posix after the delete + make split will need to make sure to incorporate those changes (Git sees file removed rather than file moved when doing these splits).

@AA-Turner
Copy link
Member

I consider that the PR is now ready for a review :-)

How would you suggest reviewing? (this is a big diff!) Should we verify that no test coverage was lost etc?

A

@vstinner
Copy link
Member Author

How would you suggest reviewing? (this is a big diff!) Should we verify that no test coverage was lost etc?

Do you like how tests are grouped? test_xxx filename and content?

@jbosboom
Copy link
Contributor

My PR was the impetus for this change, so it seemed appropriate that I scroll through it, but it's a large diff and I'm not familiar with most of the tests, so my review shouldn't count for much.

I didn't see anything technically wrong with the implementation. The test groups in the files seem reasonable to me. Many of the files end with a class PosixTester that could be named better and/or could have its test functions moved into one of the other test classes in that file. I don't think this matters given the file-level grouping, but if you ask, I will provide suggestions.

I think running the test coverage utilities on all the supported platforms would be useful to check that no coverage was lost. Is there a CI action for that?

The blank line spacing in the created files is inconsistent. Some classes have blank lines between the header and the first method, while others don't. Most classes are separated from the next by two lines, but some have three. I don't consider this important, but I don't maintain the tests. :)

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think splitting tests into separate files for each function is too much. We have separate classes for grouping.

I see only one natural way to split the tests -- for functions implemented in C (in posix/nt modules) and pure Python functions defined in the os module. Maybe move some Windows and macOS specific tests into separate files -- if we are sure that they will never be relevant on other platforms.

@vstinner
Copy link
Member Author

I think splitting tests into separate files for each function is too much. We have separate classes for grouping.

I tried to have around 1,000 lines per Python file:

$ wc -l Lib/test/test_os/*.py|sort -n
     6 Lib/test/test_os/__init__.py
    22 Lib/test/test_os/utils.py
   121 Lib/test/test_os/test_encoding.py
   121 Lib/test/test_os/test_fspath.py
   183 Lib/test/test_os/test_random.py
   187 Lib/test/test_os/test_terminal.py
   205 Lib/test/test_os/test_link.py
   227 Lib/test/test_os/test_scheduler.py
   228 Lib/test/test_os/test_dirfd.py
   242 Lib/test/test_os/test_sendfile.py
   260 Lib/test/test_os/test_user.py
   275 Lib/test/test_os/test_macos_weaklink.py
   301 Lib/test/test_os/test_stat.py
   337 Lib/test/test_os/test_fd.py
   345 Lib/test/test_os/test_timerfd.py
   357 Lib/test/test_os/test_utime.py
   388 Lib/test/test_os/test_scandir.py
   401 Lib/test/test_os/test_environ.py
   497 Lib/test/test_os/test_misc.py
   518 Lib/test/test_os/test_file_attrs.py
   690 Lib/test/test_os/test_windows.py
   766 Lib/test/test_os/test_dirs.py
   954 Lib/test/test_os/test_file.py
  1033 Lib/test/test_os/test_process.py
  8664 total

In practice, files are between 100 and 500 lines except of test_windows, test_dirs, test_file and test_process (which are between 690 and 1,033 lines).

I see only one natural way to split the tests -- for functions implemented in C (in posix/nt modules) and pure Python functions defined in the os module.

I don't think that we can make test_os and test_posix under 1,000 lines by the way.

Maybe move some Windows and macOS specific tests into separate files -- if we are sure that they will never be relevant on other platforms.

test_windodws contain all tests which are specific to Windows.

@vstinner
Copy link
Member Author

vstinner commented Oct 1, 2025

@serhiy-storchaka is against this split, so I created #139453 which only creates test_windows.

@vstinner vstinner closed this Oct 1, 2025
@vstinner vstinner deleted the test_os_package branch October 1, 2025 14:52
@vstinner
Copy link
Member Author

vstinner commented Oct 1, 2025

Follow-up: I created #139480 to create test_os.test_process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants